// 入口
module.exports = function (app) {
  const logger = require("../common/logger")
  const sequelize = require('../db/sequelize').sequelize;

  // 引入token验证
  const authhs256 = require('../middlewares/authhs256/authentication');




  sequelize.authenticate().then(() => {
    sequelize.sync();
    logger.info("mysql数据库连接成功!")
    //引入路由



    // catch 404 and forward to error handler
    app.use((req, res, next) => {
      const err = new Error('Not Found');
      err.status = 404;
      next(err);
    });
    // error handler
    app.use((err, req, res, next) => {
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get('env') === 'development' ? err : {};

      // render the error page
      res.status(err.status || 500);
      res.render('error');
    });
  }).catch(err => {
    logger.error(err)
    app.use((req, res, next) => {
      return res.json({
        code: 203,
        mes: '请检查数据库网络连通性'
      });
    });
  })
};
